package com.siti.kindnessplatform.click.mapper;

import com.siti.kindnessplatform.click.po.Encourage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;


public interface EncourageMapper extends Mapper<Encourage> {

    @Insert({"<script>",
            " INSERT INTO `sarikindnessplat`.`encourage` (\n" +
                    "  `hospital_name`,\n" +
                    "  `click_ip`) \n" +
                    "VALUES\n" +
                    "  (#{hospitalName},\n" +
                    "    #{clickIp}) ;\n" +
                    "\n" +
                    "</script>"})
    int insertEncourage(@Param("hospitalName") String hospitalName, @Param("clickIp") String clickIp);

    @Select({"<script>",
            "SELECT \n" +
                    "  `hospital_name`,\n" +
                    "  `click_ip`,\n" +
                    "  `occour_time` \n" +
                    "FROM\n" +
                    "  `sarikindnessplat`.`encourage` where hospital_name=#{hospitalName}" +
                    " and click_ip=#{clickIp}" +
                    "</script>"})
    Encourage selectEncourageById(@Param("hospitalName") String hospitalName,@Param("clickIp") String clickIp);

    @Update({"<script>",
            "update `sarikindnessplat`.`hospital` set encourage_num=encourage_num+1" +
                    " where hospital_name=#{hospitalName}" +
                    "</script>"})
    int updateHospitalById(@Param("hospitalName") String hospitalName);
}
